<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.laputa.service.model.MainFrameData"%>
<%@ page import="com.laputa.model.User"%>
<%@ page import="com.laputa.service.model.FriendListData"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
    <head>
    	<base href="<%=basePath%>">	
		<link rel="stylesheet" type="text/css" href="css/main.css">
		<%
			List<User> friends = ((FriendListData) request.getAttribute("friendListData")).getUserList();
			User[] arrayFriends = friends.toArray(new User[] {});
		 %>

		<script>
			function reset(friendID, friendName, email) {
				var tb = document.getElementById('friendInfo');
				var rowNum = tb.rows.length;
				for (i = 0; i < rowNum; i++) {
					tb.deleteRow(i);
					rowNum = rowNum - 1;
					i = i - 1;
				}
		
				var newRow = tb.insertRow(0);
				var userName = friendName;
				var line;
				line = "<tr align=\"center\">"
						+ "<td align=\"center\" valign = \"top\"><font size=\"6\"> 好友姓名:"
				line = line + userName + "</font></td></tr>"
				newRow.insertCell(0).innerHTML = line;
				
				var newRow = tb.insertRow(1);
				var userEmail = email;
				line = "<tr align=\"center\">"
						+ "<td align=\"center\" valign = \"top\"><font size=\"6\"> 好友邮箱:"
				line = line + userEmail + "</font></td></tr>"
				newRow.insertCell(0).innerHTML = line;

				var newRow = tb.insertRow(2);
				line = "<form method=\"post\" action=\"friendList.do\">" + "\n" +
					"<input type=\"hidden\" name=\"userID\" value=\"" + friendID + "\"/>" + "\n" +
					"<input type=\"submit\" name=\"showSingle\" value=\"查看页面\"/><br/>" + "\n" +
					"</form>";
				
				newRow.insertCell(0).innerHTML = line;
			}
		</script>

	</head>
	<body background="pic/background.jpg">
	<table id="banner" width="100%">
		<tr>
			<td align="center">
				<img src="pic/head.jpg" width="1000" height="100" hspace="100">
			</td>
    	</tr>
	</table>

	<table id="banner" width="100%">
		<tr>
			<td align="right">
				<form method="post" action="login.do">
					<input type="submit" name="home" value="返回" />
				</form>
			</td>
    	</tr>
	</table>
	
	<table width="250" border="0" cellspacing="1" cellpadding="0" align="right"> 	
		<tr align="center">
			<td align="center" valign="top">
				<font color="black" size="6">您的好友列表:</font>
			</td>
		</tr>
		<% 
			for (int i=0; i < arrayFriends.length; i++)
			{
				User user = arrayFriends[i];
				String id = user.getId().toString();	
			  	String friendName = user.getName();
			  	String email = user.getEmail();
				out.print("<tr align=\"center\">");
				out.print("<td align=\"center\" valign=\"top\"" +  
						"onclick=reset(\"" + id + "\",\"" + friendName +"\",\"" +email+ "\")>" +
						"<font color=\"black\" size=\"5\">" + friendName + "</font></td>");
				out.print("</tr>");
			}
		%>
		<tr align="center">
			<td align="center" valign="top">
				<form method="post" action="friendList.do">
					<input type="text" name="friendName"/>
					<input type="submit" name="addFriend" value="加好友"/>
				</form>
			</td>
		</tr>	
	</table>
	
	<table id="friendInfo" width="550" border="0" 
			cellspacing="0" cellpadding="0" align="right"> 
	</table>
	
	</body>
</html>
